package com.example.mpandroidchart1107;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;

import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.RadarDataSet;
import com.github.mikephil.charting.data.RadarEntry;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;

import java.util.ArrayList;
import java.util.List;

public class Main4Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        //1.实例化
        RadarChart chart= findViewById(R.id.chart1);
        setTitle("雷达图");

        /*3.填充数据*/
        List<IRadarDataSet> s=new ArrayList<>();

        float[] f1={80f,80f,80f,80f,80f};//数据1
        RadarDataSet d1=getDataSet(f1,"韩信");
        s.add(d1);
        d1.setColor(Color.parseColor("#00FF7F"));//线条颜色
        d1.setDrawFilled(true);/*是否填充*/


        float[] f2={80f,85f,70f,84f,86f};//数据2
        RadarDataSet d2=getDataSet(f2,"李白");
        s.add(d2);
        d2.setColor(Color.parseColor("#1E90FF"));//线条颜色
        d2.setDrawFilled(true);/*是否填充*/


        RadarData data=new RadarData(s);
        chart.setData(data);
        chart.invalidate();//清除数据，

    }

    /*2.*/
    private RadarDataSet getDataSet(float [] data,String title){

        List<RadarEntry> list=new ArrayList<>();
        for (int i=0; i<data.length;i++){
            RadarEntry radarEntry=new RadarEntry(data[i]);
            list.add(radarEntry) ;
        }
        return new RadarDataSet(list,title);//
    }
   // private final String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};

}
